﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CourseSystem.Core.BLL;
using CourseSystem.Core.Entities;

namespace CourseSystem.Common.Helpers
{
    public class TopicsHelper
    {
        public static bool IsTodayHasPost(TopicsInfo info)
        {
            if (info != null)
            {
                if (info.LastPosterId == 0 || info.LastPostTime.ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd"))
                {
                    return false;
                }
                return true;
            }
            return false;
        }

        public static bool EditLastUpdate(int tid)
        {
            var info = TopicsBLL.Get(tid);
            if (info == null)
                return false;
            info.LastPosterId = UserHelper.LoginUser.Id;
            info.LastPosterName = UserHelper.LoginUser.UserName;
            info.LastPosterType = UserHelper.GetLoginUserType();
            info.LastPostTime = DateTime.Now;
            info.Replies++;
            return TopicsBLL.Edit(info);
        }
    }
}
